//
// Created by 原帅 on 2022/9/28.
//

#include "RApp.h"
#include "RLog.h"
#include "RProcUnit.h"

RApp &RApp::DefaultInst() {
    static RApp rApp;
    return rApp;
}

int RApp::run(int argc,char** argv) {

    /// 初始化程序
    int iRet = 0;
    iRet = rInitializer.startInitialize(argc,argv);
    if (0!=iRet) return iRet;

    /// 程序运行runloop
    RLogDbg("start runloop ....")
    int iFuse = 1; /// 保险丝变量，熔断该变量，程序跳出死循环，调试程序专用变量
    while (running && iFuse) {
        iRet = rProcessor.process();
        if (0!=iRet) break;
    }
    RLogErr("runloop finished!")
    rFinisher.finish();
    RLogErr("-----------------APP finished,shutdown app-----------------");
    return iRet;
}

int RApp::stop() {
    running = false;
    return 0;
}

int RApp::registerProcUnit(RProcUnit *procUnit) {
    this->registerInitProc(procUnit);
    this->registerProc(procUnit);
    this->registerFinProc(procUnit);
    return 0;
}

int RApp::registerInitProc(RInitProcIF *rInitProcIf) {
    return this->rInitializer.registerInitProc(rInitProcIf);
    return 0;
}

int RApp::registerProc(RProcIF *rProcIf) {
    return this->rProcessor.registerProc(rProcIf);
}

int RApp::registerFinProc(RFinProcIF *rFinProcIf) {
    return this->rFinisher.registerFinProc(rFinProcIf);
}


